<?php

/**
 * Created by PhpStorm.
 * User: lcw-home
 * Date: 2015/11/14
 * Time: 16:23
 */
namespace Common\Lib;
class Response
{
    static $rArray;
    public static function redirectUrl($url,$target,$time=0){
        self::$rArray['redirect']=array('url'=>$url,'target'=>$target,'time'=>$time);
    }

    public static function info($title,$content){

    }
    public static function error($msg=''){
        self::$rArray['result']=array('status'=>'500','title'=>L('OPERATION_ERROR'),'content'=>$msg);
    }
    public static function success($msg=''){
        self::$rArray['result']=array('status'=>'200','title'=>L('OPERATION_SUCCESS'),'content'=>$msg);
    }
    public static function failed($msg=''){
        self::$rArray['result']=array('status'=>'400','title'=>L('OPERATION_FAILED'),'content'=>$msg);
    }
    public static function result($status,$title,$content){
        self::$rArray['result']=compact($status,$title,$content);
    }
    public static function go(){
        $res= '<?xml version="1.0" encoding="UTF-8"?><root>'.self::array2xml(self::$rArray).'</root>';
        header("Content-type:text/xml; charset=utf-8");
        echo $res;
        exit;
    }
    static function array2xml($array){
        $xml='';
        foreach($array as $key => $value){
            if(is_array($value)){
                $inner= self::array2xml($value);
                $xml.=sprintf('<%s>%s</%s>',$key,$inner,$key);
            }else{
                if(!isUtf8($value))
                    $value=iconv('gb2312','utf-8',$value);
                $xml.=sprintf('<%s><![CDATA[%s]]></%s>',$key,$value,$key);
            }
        }
        return $xml;
    }


}